require("../util.js");
require("../component/components.js");
require("../component/selfmediaflow.js");
require("../component/selfmediaslide.js");
require("../component/basicSlide.js");
require("../../jsMt/util.js");
var vm = new Vue({
    el:"#selfMediaPage",
    data:{
        isClassify:"",
        loadFlag:false,
        categoryId:"",
        name:"",
        categoryCarouselList:{},//顶部轮播
        categorytopList:{},//top10列表
        version:"1",
        chinaList:{
            provinces:[],//省
            cities:[],//市
            areas:[]//县
        },//中国省市列表
        provinceId:"",
        cityId:"",
        citiesList:[],//市列表
        areasList:[] //区列表
    },
    mounted:function(){
        this.searchObject = this.getQueryStringArgs();
        this.categoryId=this.searchObject&&this.searchObject.categoryId;
        this.name=decodeURI(this.searchObject&&this.searchObject.name);
        console.log(this.name);
        this.getCategoryCarouselList();
        this.getCategoryTop10List();
        this.getChinaList();
        lazyload();
    },
    methods:{
        //后退
        getBack:function(){
            history.go(-1);
        },
        bgimg:function(url){
            url = url?url:"";
            return {
                "background-image":'url("'+url+'"),url("")'
            }
        },
        /*获取查询字符对象*/
        getQueryStringArgs: function () {
            //取得查询字符串并去掉开头的问号
            var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
                args = {},
                items = qs.length ? qs.split("&") : [],
                item = null,
                name = null,
                value = null,
                len = items.length;
            for (var i = 0; i < len; i++) {
                item = items[i].split("=");
                name = item[0];
                value = item[1];
                if (name.length) {
                    args[name] = value;
                }
            }
            return args;
        },
        //顶部轮播图
        getCategoryCarouselList:function(){
            var that=this;
            this.ajax({url:"/selfMedia/getCategoryCarouselList",data:{categoryId:that.categoryId},dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.categoryCarouselList=b.json.data;
                    console.log(that.categoryCarouselList)
                }else{
                    vm.$refs.prompt.toast("获取轮播失败！")
                }
            });
        },
        //获取自媒体分类top10列表
        getCategoryTop10List:function(){
            var that=this;
            this.ajax({url:"/selfMedia/getCategoryTop10List",data:{categoryId:that.categoryId},dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.categorytopList=b.json.data;
                    console.log(that.categorytopList)
                }else{
                    vm.$refs.prompt.toast("获取top10列表失败！")
                }
            });
        },
        //获取中国省市区列表
        getChinaList:function(){
            var that=this;
            this.ajax({url:"/selfMedia/getChinaList",data:{version:that.version},dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.chinaList=b.json.data;
                    console.log(that.chinaList)
                }else{
                    vm.$refs.prompt.toast("获取省市列表失败！")
                }
            });
        },
        //获取市
        getCity:function(code){
            console.log(code);
            var that=this;
            that.citiesList=[];
            that.areasList=[];
            that.provinceId=code;
            that.chinaList.cities.forEach(function(item,index){
                if(item.provinceId==code){
                    that.citiesList.push(item);
                }

            });
            console.log(that.citiesList);
        },
        //获取区
        getAreas:function(code){
            console.log(code);
            var that=this;
            that.areasList=[];
            that.cityId=code;
            that.chinaList.areas.forEach(function(item,index){
                // console.log(item.code)
                if(item.cityId==code){
                    console.log(item.name);
                    that.areasList.push(item);
                }
            });
            console.log(that.areasList);
        },
        //显示弹框
        isDisplay:function(num){
            this.isClassify=num;
        },
        //关闭弹框
        closeClassify:function(){
            this.isClassify="";
        }
    }
});
function lazyload(){
    $("img.lazy").lazyload();
}